package category;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import yxnote.Category;

import yxnote.PMF;

public class Delete extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        
        String id = req.getParameter("id");
        
        try {
            Key k = KeyFactory.createKey(Category.class.getSimpleName(), Long.valueOf(id));
            Category category = pm.getObjectById(Category.class, Long.valueOf(id));
            pm.deletePersistent(category);
        } finally {
            pm.close();
        }
        
        resp.sendRedirect("/category/index.jsp");
    }
}
